---
import { prod } from 'astro-pure/server'
import type { SiteMeta } from 'astro-pure/types'
import config from '@/site-config'

type Props = SiteMeta

const { articleDate, description, ogImage, title } = Astro.props

const siteTitle = `${title} ${config.titleDelimiter} ${config.title}`
const canonicalURL = new URL(Astro.url.pathname, Astro.site)
const socialImageURL = new URL(ogImage ? ogImage : '/images/social-card.png', Astro.url).href
---

<meta charset='utf-8' />
<meta content='width=device-width, initial-scale=1.0, shrink-to-fit=no' name='viewport' />
<meta content='IE=edge' http-equiv='X-UA-Compatible' />
<title>{siteTitle}</title>

{/* Icons / Favicon */}
<link rel='apple-touch-icon' sizes='180x180' href='/favicon/apple-touch-icon.png' />
<link rel='icon' type='image/png' sizes='32x32' href='/favicon/favicon-32x32.png' />
<link rel='icon' type='image/png' sizes='16x16' href='/favicon/favicon-16x16.png' />
<link rel='manifest' href='/favicon/site.webmanifest' />

{/* Font preloads */}
<link rel='preload' href='/fonts/Satoshi-Variable.ttf' as='font' type='font/ttf' crossorigin />
<link
  rel='preload'
  href='/fonts/Satoshi-VariableItalic.ttf'
  as='font'
  type='font/ttf'
  crossorigin
/>

{/* Canonical URL */}
<link rel='canonical' href={canonicalURL} />

{/* Primary Meta Tags */}
<meta content={siteTitle} name='title' />
<meta content={description} name='description' />
<meta content={config.author} name='author' />

{/* Theme Color */}
<meta content='' name='theme-color' />

{/* Open Graph / Facebook */}
<meta content={articleDate ? 'article' : 'website'} property='og:type' />
<meta content={title} property='og:title' />
<meta content={description} property='og:description' />
<meta content={canonicalURL} property='og:url' />
<meta content={config.title} property='og:site_name' />
<meta content={config.locale.attrs} property='og:locale' />
<meta content={socialImageURL} property='og:image' />
<meta content='1200' property='og:image:width' />
<meta content='630' property='og:image:height' />
{
  articleDate && (
    <>
      <meta content={config.author} property='article:author' />
      <meta content={articleDate} property='article:published_time' />
    </>
  )
}

{/* Twitter */}
<meta content='summary_large_image' property='twitter:card' />
<meta content={canonicalURL} property='twitter:url' />
<meta content={title} property='twitter:title' />
<meta content={description} property='twitter:description' />
<meta content={socialImageURL} property='twitter:image' />

{/* Sitemap */}
<link href='/sitemap-index.xml' rel='sitemap' />

{/* RSS auto-discovery */}
<link
  rel='alternate'
  type='application/rss+xml'
  title={config.title}
  href={`${Astro.site}rss.xml`}
/>

<meta content={Astro.generator} name='generator' />

{/* Styles */}
<link rel='stylesheet' href='/styles/global.css' />

{
  /* User script*/
  prod && (
    <script>
      console.log( '%c Astro Theme Pure %c https://github.com/cworld1/astro-theme-pure/',
      'color:#fff;background:linear-gradient(90deg,#448bff,#44e9ff);padding:5px 0;',
      'color:#000;background:linear-gradient(90deg,#44e9ff,#ffffff);padding:5px 10px 5px 0px;' )
    </script>
  )
}
